package com.love.travel.controller;

import java.util.*;
import java.io.IOException;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.love.travel.enums.TagCategoryEnum;
import com.love.travel.enums.TagTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.love.common.log.annotation.Log;
import com.love.common.log.enums.BusinessType;
import com.love.common.security.annotation.RequiresPermissions;
import com.love.travel.domain.TravelTag;
import com.love.travel.service.ITravelTagService;
import com.love.common.core.web.controller.BaseController;
import com.love.common.core.web.domain.AjaxResult;
import com.love.common.core.utils.poi.ExcelUtil;
import com.love.common.core.web.page.TableDataInfo;

/**
 * 旅游标签Controller
 * 
 * @author love
 * @date 2025-10-18
 */
@RestController
@RequestMapping("/tag")
public class TravelTagController extends BaseController
{
    @Autowired
    private ITravelTagService travelTagService;

    /**
     * 查询旅游标签列表
     */
    @RequiresPermissions("travel:tag:list")
    @GetMapping("/list")
    public TableDataInfo list(TravelTag travelTag)
    {
        startPage();
        List<TravelTag> list = travelTagService.selectTravelTagList(travelTag);
        return getDataTable(list);
    }

    /**
     * 查询旅游标签列表
     */
    @GetMapping("/listFromAttraction")
    public TableDataInfo listFromAttraction(TravelTag travelTag)
    {
        List<TravelTag> list = travelTagService.selectTravelTagList(travelTag);
        return getDataTable(list);
    }

    @GetMapping("/listByCategory")
    public TableDataInfo listByCategory(TravelTag travelTag)
    {
        List<TravelTag> list = travelTagService.selectTravelTagByCategoryList(travelTag);
        return getDataTable(list);
    }

    /**
     * 导出旅游标签列表
     */
    @RequiresPermissions("travel:tag:export")
    @Log(title = "旅游标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelTag travelTag)
    {
        List<TravelTag> list = travelTagService.selectTravelTagList(travelTag);
        ExcelUtil<TravelTag> util = new ExcelUtil<TravelTag>(TravelTag.class);
        util.exportExcel(response, list, "旅游标签数据");
    }

    /**
     * 获取旅游标签详细信息
     */
    @RequiresPermissions("travel:tag:query")
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId)
    {
        return success(travelTagService.selectTravelTagByTagId(tagId));
    }

    /**
     * 新增旅游标签
     */
    @RequiresPermissions("travel:tag:add")
    @Log(title = "旅游标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelTag travelTag)
    {
        return toAjax(travelTagService.insertTravelTag(travelTag));
    }

    /**
     * 修改旅游标签
     */
    @RequiresPermissions("travel:tag:edit")
    @Log(title = "旅游标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelTag travelTag)
    {
        return toAjax(travelTagService.updateTravelTag(travelTag));
    }

    /**
     * 删除旅游标签
     */
    @RequiresPermissions("travel:tag:remove")
    @Log(title = "旅游标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagIds}")
    public AjaxResult remove(@PathVariable Long[] tagIds)
    {
        return toAjax(travelTagService.deleteTravelTagByTagIds(tagIds));
    }

    /**
     * 获取景观大类枚举
     */
    @GetMapping("/getTagCategoryList")
    public AjaxResult getTagCategoryList() {
        List<Map<String, String>> resultList = new ArrayList<>();
        for (TagCategoryEnum category : TagCategoryEnum.values()) {
            Map<String, String> categoryMap = new HashMap<>();
            categoryMap.put("code", category.getCode());
            categoryMap.put("desc", category.getDesc());
            resultList.add(categoryMap);
        }
        return AjaxResult.success(resultList);
    }

    /**
     * 获取景观大类枚举
     */
    @GetMapping("/getTagTypeList")
    public AjaxResult getTagTypeList() {
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (TagTypeEnum type : TagTypeEnum.values()) {
            Map<String, Object> typeMap = new HashMap<>();
            typeMap.put("code", type.getCode());
            typeMap.put("desc", type.getDesc());
            resultList.add(typeMap);
        }
        return AjaxResult.success(resultList);
    }
}
